{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP 

script_name "ChatCar"

repeat
wait 500
0AF0: 1@ = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "Loaded11"
until 1@ == 1
1@ = 0
0AF1: write_int 1@ to_ini_file "cleo\PedsModels.ini" section "Models" key "Loaded11"

0AF0: 29@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "In car Event" key "TimePause"
29@ *= 1000

0AF0: 0@ = read_int_from_ini_file "cleo\Busy Pedestrians.ini" section "Settings" key "In car Event"
if
    0@ == 0
then
    0A93: terminate_this_custom_script
end

const
    drink1 = 21@
    drink2 = 22@
    drink3 = 23@
    read1 = 24@
    read2 = 25@
    read3 = 26@
end

0AF0: read1 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "book"
0AF0: read2 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "book2"
0AF0: read3 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "paper"


0AF0: drink1 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "Drink1"
0AF0: drink2 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "Drink2"
0AF0: drink3 = read_int_from_ini_file "cleo\PedsModels.ini" section "Models" key "Drink3"


wait 5000

:ChatCar
wait 500
if
   Player.Defined($PLAYER_CHAR) 
jf @ChatCar
    if and
    $ACTIVE_INTERIOR == 0
    TIMERA < 3000
    810F:   not player $PLAYER_CHAR wanted_level > 0
    $ONMISSION == 0
jf @ChatCar_Time
    30@ = 0
    while 0EA8: get_any_car_no_save_recursive 30@ progress_to 30@ car_to 0@
        046C: 4@ = car 0@ drive
        if and
            0EE5: locate_char_distance_to_car $player_actor car 0@ radius 50.0
            not  locate_char_distance_to_car $player_actor car 0@ radius 15.0
            not 4@ == -1
        then
            0E12: get_vehicle 0@ subclass_to 1@
            if and
                82CA:   not car 0@ bounding_sphere_visible
                0431: car 0@ passenger_seat_free 1
                0431: car 0@ passenger_seat_free 2
                not is_car_script_controlled 0@
                not is_char_script_controlled 4@
                1@ == 0
            then
                089F: get_actor 4@ pedtype_to 1@
            if or
                1@ == 4
                1@ == 5
            then
                0209: 1@ = random_int_in_ranges 1 5
                if 1@ == 1
                then jump @ChatCar_Chat
                end
                if 1@ == 2
                then jump @ChatCar_Phone
                end
                if 1@ == 3
                then jump @ChatCar_Drink
                end
                if 1@ == 4
                then jump @ChatCar_Read
                end
                break
            end
        end
    end
end
jump @ChatCar

:ChatCar_Chat
04C4: store_coords_to 1@ 2@ 3@ from_actor 4@ with_offset 0.0 0.0 5.0
0376: 5@ = create_random_actor_at 1@ 2@ 3@
0376: 6@ = create_random_actor_at 1@ 2@ 3@

0430: put_actor 5@ into_car 0@ passenger_seat 1
0430: put_actor 6@ into_car 0@ passenger_seat 2
01C2: remove_references_to_actor 5@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 6@ // Like turning an actor into a random pedestrian
if and
056D:   actor 5@ defined
056D:   actor 6@ defined
then
0430: put_actor 5@ into_car 0@ passenger_seat 1
0430: put_actor 6@ into_car 0@ passenger_seat 2
060A: create_decision_maker_type 0 store_to 1@ // decision\allowed\m_.ped files
060B: set_actor 5@ decision_maker_to 1@
060B: set_actor 6@ decision_maker_to 1@
0E24: fix_char 5@ ground 0 brightness 1 and_fade_in 0
0E24: fix_char 6@ ground 0 brightness 1 and_fade_in 0
end
0006: TIMERA = 0

:ChatCar_Anim
wait 0
04ED: load_animation  "PedEventsMod"
if
04EE:   animation "PedEventsMod" loaded
jf @ChatCar_Anim

:ChatCar_2
wait 0 
if and
056D:   actor 4@ defined
056D:   actor 5@ defined
056D:   actor 6@ defined
056E:   car 0@ defined
jf @ChatCar_Exit
if and
not actor.Dead(5@)
not actor.Dead(6@)
00DB:   actor 5@ in_car 0@
00DB:   actor 6@ in_car 0@
00DB:   actor 4@ in_car 0@
81F4:   not car 0@ flipped 
8495:   not car 0@ burning
jf @ChatCar_Exit_2

if
    02CA:   car 0@ bounding_sphere_visible
then
    if and
        10@ == 0
        0019:   TIMERA > 4000
    then
        10@ = 1
        0209: 3@ = random_int_in_ranges 1 13
        0AD3: 15@v = string_format "ChatCar_%d" 3@
        0605: actor 5@ perform_animation 15@v IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end


    if and
        10@ == 1
        0019:   TIMERA > 8000
    then
        10@ = 0
        0209: 3@ = random_int_in_ranges 1 13
        0AD3: 15@v = string_format "ChatCar_%d" 3@
        0605: actor 6@ perform_animation 15@v IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
        0006: TIMERA = 0
    end
end
jump @ChatCar_2

:ChatCar_Exit_2
if and 
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
then
05CD: AS_actor 5@ exit_car 0@
end
if and 
not actor.Dead(6@)
00DB:   actor 6@ in_car 0@
then
05CD: AS_actor 6@ exit_car 0@
end

:ChatCar_Exit
04EF: release_animation "PedEventsMod"

:ChatCar_Time
wait 29@
0006: TIMERA = 0
jump @ChatCar


/// phone


:ChatCar_Phone
04C4: store_coords_to 1@ 2@ 3@ from_actor 4@ with_offset 0.0 0.0 5.0
0376: 5@ = create_random_actor_at 1@ 2@ 3@
0209: 1@ = random_int_in_ranges 1 3
0430: put_actor 5@ into_car 0@ passenger_seat 1@
01C2: remove_references_to_actor 5@ // Like turning an actor into a random pedestrian
if and
056D:   actor 5@ defined
056D:   actor 4@ defined
then
0430: put_actor 5@ into_car 0@ passenger_seat 1@
060A: create_decision_maker_type 0 store_to 1@ // decision\allowed\m_.ped files
060B: set_actor 5@ decision_maker_to 1@
model.Load(330)
038B: load_requested_models
0E2E: create_render_object_to_char_bone 5@ model 330 bone 24 offset 0 0 0 rotation 0 0 0 store_to 31@
0E30: set_render_object_auto_hide 31@ dead 1 weapon 1 car 0
model.Destroy(330)
0E24: fix_char 5@ ground 0 brightness 1 and_fade_in 0
end
0006: TIMERA = 0

:ChatCar_Phone_2
wait 0
if and
056D:   actor 4@ defined
056D:   actor 5@ defined
056E:   car 0@ defined
jf @ChatCar_Time
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
00DB:   actor 4@ in_car 0@
81F4:   not car 0@ flipped
8495:   not car 0@ burning
jf @ChatCar_Exit_Phone_2

if
    02CA:   car 0@ bounding_sphere_visible
then
    if and
        10@ == 0
        0019:   TIMERA > 5000
    then
        10@ = 1
        0605: actor 5@ perform_animation "Phone_talk" IFP "PED" framedelta 4.0 loop 1 lockX 0 lockY 0 lockF 0 time -1
    end


    if and
        10@ == 1
        0019:   TIMERA > 40000
    then
        10@ = 0
        0006: TIMERA = 0
    end
end
jump @ChatCar_Phone_2

:ChatCar_Exit_Phone_2
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
then
05CD: AS_actor 5@ exit_car 0@
0E2F: delete_render_object 31@
end
jump @ChatCar_Time


// drink


:ChatCar_Drink
04C4: store_coords_to 1@ 2@ 3@ from_actor 4@ with_offset 0.0 0.0 5.0
0376: 5@ = create_random_actor_at 1@ 2@ 3@
0209: 1@ = random_int_in_ranges 1 3
0430: put_actor 5@ into_car 0@ passenger_seat 1@
01C2: remove_references_to_actor 5@ // Like turning an actor into a random pedestrian
if and
056D:   actor 5@ defined
056D:   actor 4@ defined
then
0430: put_actor 5@ into_car 0@ passenger_seat 1@
060A: create_decision_maker_type 0 store_to 1@ // decision\allowed\m_.ped files
060B: set_actor 5@ decision_maker_to 1@
0E24: fix_char 5@ ground 0 brightness 1 and_fade_in 0

0209: 3@ = random_int_in_ranges 1 4
if
3@ == 1
then
0085: 1@ = drink1 // (int)
end
if
3@ == 2
then
0085: 1@ = drink2 // (int)
end
if
3@ == 3
then
0085: 1@ = drink3 // (int)
end
0F02:  5@ special_model 1@ bone 24 offset 0.04 0.05 0.0 rotation 0 0 0 scale 31@ // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors
0E30: set_render_object_auto_hide 31@ dead 1 weapon 1 car 0
end
0006: TIMERA = 0

:ChatCar_Anim_Drink
wait 0
04ED: load_animation  "PedEventsMod"
if
04EE:   animation "PedEventsMod" loaded
jf @ChatCar_Anim_Drink


:ChatCar_Drink_2
wait 0
if and
056D:   actor 4@ defined
056D:   actor 5@ defined
056E:   car 0@ defined
jf @ChatCar_Exit
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
00DB:   actor 4@ in_car 0@
81F4:   not car 0@ flipped
8495:   not car 0@ burning
jf @ChatCar_Exit_Drink_2

if
    02CA:   car 0@ bounding_sphere_visible
then
    if and
        10@ == 0
        0019:   TIMERA > 5000
    then
        10@ = 1
        0605: actor 5@ perform_animation "DrinkCar" IFP "PedEventsMod" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
    end


    if and
        10@ == 1
        0019:   TIMERA > 15000
    then
        10@ = 0
        0006: TIMERA = 0
    end
end
jump @ChatCar_Drink_2

:ChatCar_Exit_Drink_2
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
then
05CD: AS_actor 5@ exit_car 0@
0E2F: delete_render_object 31@
end
jump @ChatCar_Exit


// Read


:ChatCar_Read
04C4: store_coords_to 1@ 2@ 3@ from_actor 4@ with_offset 0.0 0.0 5.0
0376: 5@ = create_random_actor_at 1@ 2@ 3@
0209: 1@ = random_int_in_ranges 1 3
0430: put_actor 5@ into_car 0@ passenger_seat 1@
01C2: remove_references_to_actor 5@ // Like turning an actor into a random pedestrian
if and
056D:   actor 5@ defined
056D:   actor 4@ defined
then
0430: put_actor 5@ into_car 0@ passenger_seat 1@
060A: create_decision_maker_type 0 store_to 1@ // decision\allowed\m_.ped files
060B: set_actor 5@ decision_maker_to 1@
0E24: fix_char 5@ ground 0 brightness 1 and_fade_in 0

2@ = 180.0
0209: 3@ = random_int_in_ranges 1 4
if
3@ == 1
then
0085: 1@ = read1 // (int)
end
if
3@ == 2
then
0085: 1@ = read2 // (int)
end
if
3@ == 3
then
0085: 1@ = read3 // (int)
2@ = 0.0
end
0F02:  5@ special_model 1@ bone 34 offset 0.25 0.03 0 rotation 0 180.0 2@ scale 31@ // bone 34 left hand, 24 right hand, 9 had, 3 tors, 4 upper tors
0E30: set_render_object_auto_hide 31@ dead 1 weapon 1 car 0
end
0006: TIMERA = 0

:ChatCar_Anim_Read
wait 0
04ED: load_animation  "PedEventsMod"
if
04EE:   animation "PedEventsMod" loaded
jf @ChatCar_Anim_Read


:ChatCar_Read_2
wait 0
if and
056D:   actor 4@ defined
056D:   actor 5@ defined
056E:   car 0@ defined
jf @ChatCar_Exit
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
00DB:   actor 4@ in_car 0@
81F4:   not car 0@ flipped
8495:   not car 0@ burning
jf @ChatCar_Exit_Read_2
if
    02CA:   car 0@ bounding_sphere_visible
then
    if and
        10@ == 0
        0019:   TIMERA > 5000
    then
        10@ = 1
        0605: actor 5@ perform_animation "ReadCar" IFP "PedEventsMod" framedelta 4.0 loop 1 lockX 0 lockY 0 lockF 0 time 10000
    end


    if and
        10@ == 1
        0019:   TIMERA > 15000
    then
        10@ = 0
        0006: TIMERA = 0
    end
end
jump @ChatCar_Read_2

:ChatCar_Exit_Read_2
if and
not actor.Dead(5@)
00DB:   actor 5@ in_car 0@
then
05CD: AS_actor 5@ exit_car 0@
0E31: set_render_object_visible 31@ 0
end
jump @ChatCar_Exit

// By ArtemQa146